// pages/rankingDeil/rankingDeil.js
const app = getApp();
const WxParse = require('../../wxParse/wxParse.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    imgurl: app.imgurl,
    rankingnav: [
      { txt: '捐赠能量种子' },
      { txt: '小天鹅所获能量种子' },
    ],
    ranking: [
      { name: '张丹丹', icon_num: '4', pic: 'icon_01.png', ads: '总部(碑林)校区', num: '1' },
      { name: '张丹丹', icon_num: '5', pic: 'icon_01.png', ads: '总部(碑林)校区', num: '5' },
      { name: '张丹丹', icon_num: '6', pic: 'icon_01.png', ads: '总部(碑林)校区', num: '10' },
    ],
    recharge: [
      { money: '30', num: '30' },
      { money: '50', num: '50'  },
      { money: '200', num: '200'  },
    ],
		paytype:false,
    navindex:0,
    num_all:false,
    value:0
  },
  pay:function(e){
    let that = this;
    if (e.currentTarget.dataset.num == null){
      wx.showToast({
        title: '请选择捐赠数量',
        icon:'none',
        mask:true
      })
      return false;
    }
    app.request({
      url: 'index/energy_seed/getOrderWeChetPay',
      method: 'post',
      type: 1,
      data: {
        num: Number(e.currentTarget.dataset.num),
        baby_id:that.data.babyid
      },
      success: function (res) {
        wx.requestPayment({
          timeStamp: res.data.timeStamp,
          nonceStr: res.data.nonceStr,
          package: res.data.package,
          signType: res.data.signType,
          paySign: res.data.paySign,
          success:function(ress){
            console.log(ress)
            wx.showToast({
              title: '支付成功',
              icon: 'none',
              mask: true
            })
            app.request({
              url: 'index/energy_seed/DonorList',
              method: 'post',
              type: 0,
              data: {
                baby_id: that.data.babyid
              },
              success: function (res) {
                that.setData({
                  data: res.data
                })
              }
            })
          },
          fail:function(err){
            wx.showToast({
              title: '支付失败',
              icon:'none',
              mask:true
            })
          }
        })
        console.log(res)
      },
    });
  },
  //选择种子数
  slider3change(event){
    var value = this.data.value;
    var evalue = event.detail.value;
    console.log(evalue)
    this.setData({
      value: evalue
    })
  },
  //关闭支付页面
  start_down(){
    this.setData({
      num_all:false
    })
  },
  //选择其他数量
  start_other(){
    this.setData({
      num_all: true
    })
  },
  //获取能量
  //选择充值
  start_chosere(e) {
    var index = e.currentTarget.dataset.index;
    var num = e.currentTarget.dataset.num;
    var recharge = this.data.recharge;
    console.log(index)
    this.setData({
      buyindex: index, num: num
    })
  },
  rankingClick: function (e) {
    var id = e.currentTarget.dataset.id;
    console.log(id)
    this.setData({
      navindex: id
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that = this;
    that.setData({ babyid: options.babyid}),
		console.log(app.paytype,'-----')
		that.setData({paytype:app.paytype})
		if(!app.paytype){
			
			return false
		}else{
			
			app.request({
				url: 'index/energy_seed/DonorList',
				method: 'post',
				type: 0,
				data: {
					baby_id: options.babyid
				},
				success: function (res) {
					that.setData({
						data:res.data
					})
				}
			})
		}		
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    let that = this;
    app.request({
      url: 'index/energy_seed/PurchaseInstructions',
      method: 'post',
      type: 0,
      success: function (res) {
        WxParse.wxParse('article', 'html', res.data.opinion, that, 5)
      }
    })
  },  

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})